package hgz.stu.review.ruijie.config.resolve;

import org.springframework.core.io.support.ResourcePatternResolver;
import org.springframework.util.StringUtils;

import hgz.stu.review.ruijie.enviroment.SkyEngineEnvType;

/**
 * Description: Function Description
 * Copyright: Copyright (c) 2017
 * Company: Ruijie Co., Ltd.
 * Create Time: 2018/8/28
 *
 * @author dell
 */
public class ExternalConfigResolver extends AbstractConfigResolver {


    public ExternalConfigResolver(ResourcePatternResolver resourceLoader) {
        super(resourceLoader);
    }

    @Override
    public boolean containsConfig() {
        return StringUtils.hasText(System.getProperty("sk.config.path") );
    }


    @Override
    String buildLocation(SkyEngineEnvType skyEngineEnvType, String moduleName) {
        String property = System.getProperty("sk.config.path");
        if(StringUtils.isEmpty(property)){
            return "";
        }
        String filePath = addFileProtocol(property);
        String modulePath = StringUtils.isEmpty(moduleName) ? "" : "/"+moduleName;
        String location = filePath + modulePath + "/*-"+ skyEngineEnvType.toString().toLowerCase()+".properties";
        return location;
    }

    private String addFileProtocol(String property) {
        return "file:"+property;
    }

    @Override
    public int getOrder() {
        return 3;
    }
}
